
		
	
/// <summary>
///  The purpose of this class is to call the appropriate classes within the partial classes
///  The purpose of this code is to dynamically build the XPATH queries that are to be used within a Pipeline to write to bam
/// </summary>
		using System;
		using System.Collections.Generic;
		using System.Text;
		using System.Xml;
		using Microsoft.BizTalk.Message.Interop;
		using Microsoft.BizTalk.Component.Interop;

		namespace Generated_BAM_Pipeline_Queries
		{
		public interface IBamMessage
		{
		System.Collections.Hashtable XPathQueries
		{get;}
		System.Collections.Hashtable XPathMethodProperties
		{ get;}
		System.Collections.Hashtable XPathContextProperties
		{ get;}
		System.Collections.Hashtable UploadContextProperties
		{ get;}
		bool HasContextProperties
		{ get;}
		bool HasUploadProperties
		{ get;}
		bool HasDataProperties
		{ get;}
		bool HasMethodProperties
		{ get;}
		int QueryCount
		{ get;}
		int ContextCount
		{ get;}
		int MethodCount
		{ get;}
		string MapName
		{ get;}
		string ActivityID
		{ get;}
		string MapLibrary
		{ get;}
		bool UseStreamingXSL
		{ get;}
		System.Xml.XmlDocument BAMActivitiesDocument
		{ get;set;}
		void TransformAndSave(Microsoft.BizTalk.Streaming.ReadOnlySeekableStream InputStream, Microsoft.BizTalk.Component.Interop.IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessageContext context, bool DirectBAMWrite, string BAMDBConnectionString, string BTSMessageID, bool SaveBody, string MessageBody);
		void SaveContextOnly(Microsoft.BizTalk.Component.Interop.IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessageContext context, bool DirectBAMWrite, string BAMDBConnectionString, string BTSMessageID, bool SaveBody, string MessageBody);
		void UploadContextPropertiesIntoMessage(Microsoft.BizTalk.Component.Interop.IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessageContext context, string BTSMessageID);
		}
		public class BAMActivityDispatcher
		{
		public static IBamMessage CreateBAMMessage(string MessageType, string ActivityName)
		{
		IBamMessage _returnMessage = null;
		if(ActivityExistsForMessage(MessageType, ActivityName))
		{if(MessageType == "AllMessageTypes")
					{
						if(ActivityName == "GeneralMessage_Info")
						{
							_returnMessage = (IBamMessage)new Generated_BAM_Pipeline_Queries.BAMActivityXPaths.AllMessageTypes_GeneralMessage_Info();
						}
					}
			if(MessageType == "X12_00401_837_I")
					{
						if(ActivityName == "CLM_837I")
						{
							_returnMessage = (IBamMessage)new Generated_BAM_Pipeline_Queries.BAMActivityXPaths.X12_00401_837_I_CLM_837I();
						}
					}
			
			}
            return _returnMessage;
        }
		public static bool ActivityExistsForMessage(string MessageType, string ActivityName)
        {
            bool retVal = false;
            
			if(MessageType == "AllMessageTypes")
			{
				if(ActivityName == "GeneralMessage_Info")
				{
					retVal=true;
				}
			
			}
		
			if(MessageType == "X12_00401_837_I")
			{
				if(ActivityName == "CLM_837I")
				{
					retVal=true;
				}
			
			}
		
            return retVal;
        }
		public static System.Collections.Hashtable GetXPathExpressions(String MessageType, System.Collections.ArrayList ActivityNames)
        {
            System.Collections.Hashtable _return = new System.Collections.Hashtable();
            foreach (string Activity in ActivityNames)
            {
				if(ActivityExistsForMessage(MessageType, Activity))
				{
					System.Collections.Hashtable _interim = new System.Collections.Hashtable();
					IBamMessage msg = CreateBAMMessage(MessageType, Activity);
					foreach (System.Collections.DictionaryEntry _de in msg.XPathQueries)
					{
						_return.Add(_de.Key, _de.Value);
					}
				}
            }
            return _return;
        }
       
		public static string GetContextNamespace(string PropertyParentItem)
        {
          switch (PropertyParentItem)
            {
				case "BTF2":
					return @"http://schemas.microsoft.com/BizTalk/2003/btf2-properties";
				case "BTS":
					return @"http://schemas.microsoft.com/BizTalk/2003/system-properties";
				case "ErrorReport":
					return @"http://schemas.microsoft.com/BizTalk/2005/error-report";
				case "FILE":
					return @"http://schemas.microsoft.com/BizTalk/2003/file-properties";
				case "FTP":
					return @"http://schemas.microsoft.com/BizTalk/2003/ftp-properties";
				case "HTTP":
					return @"http://schemas.microsoft.com/BizTalk/2003/http-properties";
				case "LEGACY":
					return @"http://schemas.microsoft.com/BizTalk/2003/legacy-properties";
				case "MessageTracking":
					return @"http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties";
				case "Microsoft":
					return @"http://schemas.microsoft.com/BizTalk/2003/xlangs-properties";
				case "MIME":
					return @"http://schemas.microsoft.com/BizTalk/2003/mime-properties";
				case "MSMQT":
					return @"http://schemas.microsoft.com/BizTalk/2003/msmqt-properties";
				case "POP3":
					return @"http://schemas.microsoft.com/BizTalk/2003/pop3-properties";
				case "SMTP":
					return @"http://schemas.microsoft.com/BizTalk/2003/smtp-properties";
				case "SOAP":
					return @"http://schemas.microsoft.com/BizTalk/2003/soap-properties";
				case "WCF":
					return @"http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties";
				case "WSS":
					return @"http://schemas.microsoft.com/BizTalk/2006/WindowsSharePointServices-properties";
				case "XMLNORM":
					return @"http://schemas.microsoft.com/BizTalk/2003/xmlnorm-properties";
				case "EDI":
					return @"http://schemas.microsoft.com/Edi/PropertySchema";
				case "EdiIntAS":
					return @"http://schemas.microsoft.com/BizTalk/2006/as2-properties";
				case "Sample_BTS_BAM_Project":
					return @"http://Sample_BTS_BAM_Project.Schemas.CustomContextSchema";
				default:
					return "Unknown";
            }
           
        }
        private static string parseXpathContextProperty(string XPathToContextProperty)
        {
            //XPath should be something like this
            //*[local-name()='ContextProperties']/*[local-name()='BuiltinContextProperties']/*[local-name()='BTS']/*[local-name()='MessageType']
            string[] splitText = XPathToContextProperty.Split('=');
            splitText = splitText[3].Split(']');
            string finalText = splitText[0].Substring(1,splitText[0].Length -2);
            return finalText;
        }
    }
}

	